package com.duying.ht.manager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.duying.ht.HtCommonManager;
import com.duying.ht.model.HtHuiqian;
import com.duying.ht.model.HtProcessItem;

public class HtProcessItemManager  extends HtCommonManager{
	public List getByProId(String proId){
		String hql = "from HtProcessItem hpi where hpi.htProcess.id =:proId order by hpi.sort asc";
		Map map = new HashMap();
		map.put("proId", proId);
		return this.baseDao.getByHQL(hql, map);
	}
	
	
	public void deleteItems(String proId){
		String hql = "delete HtProcessItem hpi where hpi.htProcess.id =:proId";
		Map map = new HashMap();
		map.put("proId", proId);
		this.baseDao.excuteByHql(hql, map);
	}
	
	
	public HtProcessItem getByProId2DeptId(String proId , Integer deptId){
		String hql = "from HtProcessItem hpi where hpi.htProcess.id =:proId and hpi.systemDept.id =:deptId";
		Map map = new HashMap();
		map.put("proId", proId);
		map.put("deptId", deptId);

		List list = this.baseDao.getByHQL(hql, map);
		if(list.isEmpty()){
			return null;
		}else{
			return (HtProcessItem)list.get(0);
		}
	}
	
	

	public HtProcessItem getTop1ByProId(String proId , HtProcessItem curItem){
		String hql = "from HtProcessItem hpi where hpi.htProcess.id =:proId ";
		// 
		Map map = new HashMap();
		map.put("proId", proId);
		
		if(curItem != null){
			hql += "and hpi.sort >:curSort ";
			map.put("curSort", curItem.getSort());
		}
		hql += "order by hpi.sort asc";
		List listItem = this.baseDao.getByHQL(hql, map);
		
		if(!listItem.isEmpty()){
			return (HtProcessItem)listItem.get(0);
		}else{
			return null;
		}
	}

	
	
}
